# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=ogreassimp

pkgbase=mingw-w64-${_realname}-hg
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-hg"
pkgver=r33.ebcbefe6e081
pkgrel=3
pkgdesc="Open Asset Import Library (Assimp) Loader for Ogre3D (mingw-w64)"
arch=('any')
url="https://www.ogre3d.org/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config" "${MINGW_PACKAGE_PREFIX}-cmake" "mercurial")
depends=("${MINGW_PACKAGE_PREFIX}-assimp"
    "${MINGW_PACKAGE_PREFIX}-ogre3d")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
options=('staticlibs' '!strip')
source=("${_realname}-${pkgver}.tar.xz"
    update-boost-part.patch
    support-ogre-1_9_0.patch
    install-fix.patch)
md5sums=('493e82095943eb79c503e13f432fabe1'
         '478b6b938d68ff50f301cea897d1c2bf'
         '6d513837ad431b9e1affb3b5ee3cb340'
         '8a785673ce46bac75309f6fb69961c18')

# source PKGBUILD && mksource
mksource() {
  [[ -x /usr/bin/hg ]] || (echo "hg not found. Install mercurial." && return 1)

  __hgroot='https://bitbucket.org/jacmoe'
  __hgrepo='ogreassimp'
  __hgbranch='default'

  hg clone "${__hgroot}/${__hgrepo}/" ${__hgrepo}
  #hg clone -b ${__hgbranch} "${__hgroot}${__hgrepo}#${__hgrev}" ${__hgrepo}

  pushd ${__hgrepo}
  if (( $(hg id -n) < $(hg id -nr ${__hgbranch}) )); then
    printf 'You are not building the latest revision!\n'
    printf "Consider updating __hgrev to $(hg id -r ${__hgbranch}).\n"
  fi
  __hgver="r$(hg identify -n).$(hg identify -i)"
  popd

  mv ${__hgrepo} ${_realname}-${__hgver}
  find ${_realname}-${__hgver} -depth -type d -name .hg -exec rm -rf {} \;
  rm ${_realname}-${__hgver}/{.hgignore,.hgtags}
  tar -cJf ${_realname}-${__hgver}.tar.xz ${_realname}-${__hgver}/*
  rm -r ${_realname}-${__hgver}

  gpg --detach-sign ${_realname}-${__hgver}.tar.xz

  #scp ${pkgname}-${pkgver}.tar.xz nym:/srv/ftp/other/vim/
  #scp ${pkgname}-${pkgver}.tar.xz.sig nym:/srv/ftp/other/vim/
}

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p0 -i ${srcdir}/update-boost-part.patch
  patch -p0 -i ${srcdir}/support-ogre-1_9_0.patch
  patch -p0 -i ${srcdir}/install-fix.patch
}

build() {
  mkdir -p ${pkgdir}${MINGW_PREFIX}
  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  export PREFIX_WIN=`pwd -W`
  popd > /dev/null

  pushd ${MINGW_PREFIX} > /dev/null
  export PREFIX_DEPS=`pwd -W`
  popd > /dev/null

  cd "${srcdir}/${_realname}-${pkgver}"
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${PREFIX_WIN} \
    -DCMAKE_BUILD_TYPE=RELEASE \
    -DFIX_NEED_ZLIB=ON
  make
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"
  make -j1 install
}
